package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.RestaurantsExample;
import it.irondev.appturismo.dao.provider.RestaurantsSqlProvider;
import it.irondev.appturismo.entity.City;
import it.irondev.appturismo.entity.Gallery;
import it.irondev.appturismo.entity.Language;
import it.irondev.appturismo.entity.Restaurant;
import it.irondev.appturismo.entity.Restauranttype;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface RestaurantsMapper {
    @SelectProvider(type=RestaurantsSqlProvider.class, method="countByExample")
    int countByExample(RestaurantsExample example);

    @DeleteProvider(type=RestaurantsSqlProvider.class, method="deleteByExample")
    int deleteByExample(RestaurantsExample example);

    @Delete({
        "delete from Restaurants",
        "where idRestaurant = #{idrestaurant,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idrestaurant);

    @Insert({
        "insert into Restaurants ( name, ",
        "description, phone, premium, ",
        "email, web, position, ",
        "city, type, language, address, maxprice, minprice)",
        "values ( #{name,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{premium,jdbcType=BOOLEAN}, ",
        "#{email,jdbcType=VARCHAR}, #{web,jdbcType=VARCHAR}, #{position,jdbcType=VARCHAR}, ",
        "#{city.idcity,jdbcType=INTEGER}, #{type.idrestauranttype,jdbcType=INTEGER}, #{language.idlanguage,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR},#{maxprice,jdbcType=INTEGER},#{minprice,jdbcType=INTEGER})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idRestaurant")

    int insert(Restaurant record);

    @InsertProvider(type=RestaurantsSqlProvider.class, method="insertSelective")
    int insertSelective(Restaurant record);

    @SelectProvider(type=RestaurantsSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idRestaurant", property="idrestaurant", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
        @Result(column="premium", property="premium", jdbcType=JdbcType.BOOLEAN),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="maxprice", property="maxprice", jdbcType=JdbcType.INTEGER),
        @Result(column="minprice", property="minprice", jdbcType=JdbcType.INTEGER),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="type", property="type", javaType=Restauranttype.class, one=@One(select="it.irondev.appturismo.dao.RestauranttypeMapper.selectByPrimaryKey")),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
    })
    List<Restaurant> selectByExample(RestaurantsExample example);

    @Select({
        "select",
        "idRestaurant, name, description, phone, email, web, position, city, type, language, address,maxprice,minprice,gallery",
        "from Restaurants",
        "where idRestaurant = #{idrestaurant,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idRestaurant", property="idrestaurant", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
        @Result(column="premium", property="premium", jdbcType=JdbcType.BOOLEAN),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="maxprice", property="maxprice", jdbcType=JdbcType.INTEGER),
        @Result(column="minprice", property="minprice", jdbcType=JdbcType.INTEGER),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="type", property="type", javaType=Restauranttype.class, one=@One(select="it.irondev.appturismo.dao.RestauranttypeMapper.selectByPrimaryKey")),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
    })
    Restaurant selectByPrimaryKey(Integer idrestaurant);

    @UpdateProvider(type=RestaurantsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Restaurant record, @Param("example") RestaurantsExample example);

    @UpdateProvider(type=RestaurantsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Restaurant record, @Param("example") RestaurantsExample example);

    @UpdateProvider(type=RestaurantsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Restaurant record);

    @Update({
        "update Restaurants",
        "set name = #{name,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "web = #{web,jdbcType=VARCHAR},",
          "position = #{position,jdbcType=VARCHAR},",
          "address = #{address,jdbcType=VARCHAR},",
          "city = #{city.idcity,jdbcType=INTEGER},",
          "maxprice = #{maxprice,jdbcType=INTEGER},",
          "minprice = #{minprice,jdbcType=INTEGER},",
          "type = #{type.idrestauranttype,jdbcType=INTEGER},",
          "language = #{language.idlanguage,jdbcType=INTEGER},",
          "gallery = #{gallery.idgallery,jdbcType=INTEGER}",
        "where idRestaurant = #{idrestaurant,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Restaurant record);
}